package com.hp.ssmp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hp.ssmp.dao.NewsMapper;
import com.hp.ssmp.entity.TGoods;
import com.hp.ssmp.entity.TNews;
import com.hp.ssmp.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("newsService")
@Transactional
public class NewsServiceImpl extends ServiceImpl<NewsMapper, TNews> implements NewsService {
    @Autowired
    private NewsMapper newsMapper;


    @Override
    public List<TNews> getPromotionNews(Long type, Long count) {
        QueryWrapper<TNews> queryWrapper = new QueryWrapper<TNews>();
        queryWrapper.eq("NEWSTYPE", type);
        queryWrapper.last("limit 0,"+count);
        return newsMapper.selectList(queryWrapper);
    }

    @Override
    public Page<TNews> getNewsPage(Integer currentPage, Integer pageSize, Long newstype) {
        Page<TNews> page = new Page<TNews>(currentPage,pageSize);
        QueryWrapper<TNews> wrapper = new QueryWrapper<TNews>();
        if(null != newstype && !"".equals(newstype)){
            wrapper.eq("newstype",newstype);
        }
        return newsMapper.selectPage(page,wrapper);
    }
}
